package com.photographysharing.exception;

import com.photographysharing.response.MessageResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 */

@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(ServiceException.class) // 处理对应的异常
    @ResponseBody
    public MessageResponse handle(ServiceException e){
        return new MessageResponse(e.getCode(),e.getMessage(),false);
    }
}
